#ifndef WRITEATTACK_TEXTEDIT_H
#define WRITEATTACK_TEXTEDIT_H

#include <deque>

#include <QtWidgets/QTextEdit>
#include <QtCore/QTimer>

// used for burning effect
struct BurnPixel
{
	BurnPixel( int _x, int _y) : x(_x), y(_y), age(0.0) {}
	
	int x, y;
	float age;

	bool operator <( const BurnPixel &other ) const
	{
		return age < other.age;
	}
};

class WriteAttackTextEdit : public QTextEdit
{
	Q_OBJECT

public:
	WriteAttackTextEdit( QWidget *parent );

	void lockDown();
	void unlockDown();

	// is locked down?
	bool lockdown();
	
	void checkSelection();

	void destroyText();

protected:
	virtual void keyPressEvent( QKeyEvent *event );

	// to disable drag-drop during edit
	virtual bool canInsertFromMimeData( const QMimeData *source ) const;

	virtual QMimeData *createMimeDataFromSelection () const;

	// override paint for destruction
	virtual void paintEvent( QPaintEvent *event );	

	// stupid... these don't work
	virtual void dragEnterEvent( QDragEnterEvent *event );
	virtual void dragLeaveEvent( QDragLeaveEvent *event );
	virtual void dragMoveEvent( QDragMoveEvent *event );	

	// for burninating
	QImage burnImage;
	QTimer burnAnimTimer;
	std::deque<BurnPixel> burnPixels;
	void doBurnPixel( int x, int y );
	QRgb burnColor( float age );

	bool isLockdown;
	bool isDestroy;

protected slots:
	void updateBurn();

signals:
	void burningDone();

};

#endif
